<?php
namespace app\admin\controller;

\think\Loader::import('controller/Controller', \think\Config::get('traits_path') , EXT);

use app\admin\Controller;
use think\Db;
use think\Loader;
use think\exception\HttpException;
use think\Config;
class PaperQuestionsItem extends Controller
{
    use \app\admin\traits\controller\Controller;
    // 方法黑名单
    protected static $blacklist = [];
    /**
     * 首页
     * @return mixed
     */
    public function item()
    {


        $map['question_id']=input("question_id");
        $listRows = $this->request->param('numPerPage') ? : config("paginate.list_rows");
        $list = DB('PaperQuestionsItem')
            ->alias('pqi')
            ->join('tp_paper_questions pq','pq.id=pqi.question_id and pq.id='.input('question_id').' and pqi.question_id='.input('question_id'),'left')
            ->join('tp_driver_rank dr','dr.id=pq.rank_id','left')
            ->field('pqi.*,dr.name as rank_name,pq.title')
            ->where($map)
            ->order("pqi.id desc")
            ->paginate($listRows, false, ['query' => $this->request->get()]);

        $this->view->assign('list',$list);
        $this->view->assign("count", $list->total());
        $this->view->assign("page", $list->render());
        $this->view->assign('numPerPage', $list->listRows());

        return $this->view->fetch();
    }
    public function beforeadd()
    {            //获取等级列表
        if($this->request->isAjax()){

            $item_type=Db::name('paper_questions')->where('id',input('question_id'))->value('type');
            $this->request->post(array('item_type'=>$item_type));
        }
    }
    /**
     * 默认删除操作
     */
    public function delete()
    {
        $model = $this->getModel();
        $pk = $model->getPk();
        $ids = $this->request->param($pk);
        $where[$pk] = ["in", $ids];
        if (false === $model->where($where)->delete()) {
            return ajax_return_adv_error($model->getError());
        }

        return ajax_return_adv("删除成功");
    }
}
